﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<ImbaTracker.Models.User>>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Members
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <h2>Members</h2>

    <p>
        <% if (ImbaTracker.Content.Helper.isProjectOwner(ImbaTracker.Content.Helper.curUserId(User)
                       , (int)ViewData["Project"]) || User.IsInRole("Administrator")) { %>
        <%: Html.ActionLink("Add member", "AddMember", new { projId = (int)ViewData["Project"] })%>
        <% } %>
    </p>

    <table>
        <tr>
            <th> Id </th>
            <th> Login </th>
            <th> Name </th>
            <th></th>
            <th></th>
        </tr>

    <% foreach (var item in Model) { %>
    
        <tr>
            <td> <%: item.Id %> </td>
            <td> <%: item.Login %> </td>
            <td> <%: item.Name %> </td>

            <td>
                <% if (ImbaTracker.Content.Helper.isProjectOwner(ImbaTracker.Content.Helper.curUserId(User)
                       , (int)ViewData["Project"]) || ImbaTracker.Content.Helper.canAccess(User, item.Id)) { %>
                <%:     Html.ActionLink("Delete", "DeleteMember", new { userId = item.Id, projId = (int)ViewData["Project"] })%>
                <% } %>
            </td>
            <td>
                <% if (ImbaTracker.Content.Helper.isProjectOwner(ImbaTracker.Content.Helper.curUserId(User)
                       , (int)ViewData["Project"]) || User.IsInRole("Administrator")) { %>
                <% if (ImbaTracker.Content.Helper.isProjectOwner(item.Id, (int)ViewData["Project"])) { %> 
                <%      if (User.Identity.Name != item.Login) { %>
                <%:         Html.ActionLink("Delete Owner", "DeleteOwner", new { userId = item.Id, projId = (int)ViewData["Project"] })%>
                <%      } %>
                <% } else { %>
                <%:     Html.ActionLink("Make Owner", "AddOwner", new { userId = item.Id, projId = (int)ViewData["Project"] })%>
                <% } %>
                <% } %>
            </td>
        </tr>
    
    <% } %>

    </table>

</asp:Content>

